package com.epic.rest;

import com.epic.inter.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;

@Path("/v1/")
@Component("UserResource")
public class UserResources {

    @Autowired
    IUserService iUserService;

    @Path("user/list")
    @GET
    @Produces("application/json;charset=UTF-8")
    public String test(@Context HttpServletRequest request,
                        @QueryParam("args") String args){
        try{
                return "hello ok";
        }catch (Exception e){
        }
        return "error";
    }


    @Path("user/add")
    @POST
    @Produces("application/json;charset=UTF-8")
    public String test2(@Context HttpServletRequest request,
                       String args){
        try{
            return "hello ok";
        }catch (Exception e){
        }
        return "error";
    }

    @Path("user/modify")
    @POST
    @Produces("application/json;charset=UTF-8")
    public String test3(@Context HttpServletRequest request,
                        String args){
        try{
            return "hello ok";
        }catch (Exception e){
        }
        return "error";
    }

    @Path("user/testpathargs/{id}")
    @DELETE
    @Produces("application/json;charset=UTF-8")
    @Consumes("application/json;charset=UTF-8")
    public String test4(@Context HttpServletRequest request,
                        @PathParam("id") String id){
        try{
            return "test pathparam " + id;
        }catch (Exception e){
        }
        return "error";
    }
}

/**
 * java.ws.rs是jax-rs规范中定义的包名
 *
 * jax-rs全称Java API for RESTful Services
 * GET，POST，PUT，DELETE和CRUD的对应关系？注意：以上CRUD增删改查（create，retrieve，update，delete）整套CRUD操作，C对应POST，R对应GET，U对应PUT，D对应DELETE
 * PUT 修改
 * POST 增加
 *
 * Producers Consumers 的解释和使用
 * The @Produces annotation is used to specify the MIME media types or representations a resource can produce and send back to the client.
 * The @Consumes annotation is used to specify which MIME media types of representations a resource can accept, or consume, from the client.
 * https://docs.oracle.com/cd/E19798-01/821-1841/gipzh/index.html
 * https://blog.csdn.net/qq_22177809/article/details/86592660
 * Producer 指定HTTP响应的MIME类型
 * Consumer 指定HTTP请求的MIME类型
 */